﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Framework
{
    public class JYFileUpdate
    {
        public static bool UpdatePicture(string url, string instid, string mchntid, string passdate, string fileName, string filePath, string sign)
        {

            var formDatas = new List<Framework.FormItemModel>();

            if (File.Exists(filePath) == false)
            {
                return false;
            }
            var fileStream = File.OpenRead(filePath);

            //添加文本
            formDatas.Add(new Framework.FormItemModel()
            {
                Key = "instid",
                Value = instid
            });
            formDatas.Add(new Framework.FormItemModel()
            {
                Key = "mchntid",
                Value = mchntid
            });
            formDatas.Add(new Framework.FormItemModel()
            {
                Key = "passdate",
                Value = passdate
            });
            //添加文件
            formDatas.Add(new Framework.FormItemModel()
            {
                Key = "file",
                Value = "",
                FileName = fileName,
                FileContent = fileStream
            });
            formDatas.Add(new Framework.FormItemModel()
            {
                Key = "sign",
                Value = sign
            });
            string result ="";
            try
            {
                //提交表单
                result = Framework.HttpHelper.PostForm(url, formDatas);
            }
            finally
            {
                fileStream.Close();
                fileStream.Dispose();
            }
            if (result.Contains("0000"))
            {
                return true;
            }
            else
            {
                return false;
            }


        }
    }
}
